package cm.wc;

import com.google.errorprone.annotations.Var;

import java.io.FileReader;
import java.io.IOException;
import java.sql.*;
import java.util.Properties;
import java.util.Scanner;

/**
 * @ClassName:jdbcdelect
 * @Author: 鹿建文
 * @Date: 2022/3/30  - 10:14
 * @Describe:
 */
public class jdbcdelect {
    private static String url;
    private static String user;
    private static String password;

    static {
        Properties properties = new Properties();
        try {
            properties.load(new FileReader("src/main/resources/mysql.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        url = properties.getProperty("url");
        user = properties.getProperty("user");
        password = properties.getProperty("password");
    }


    public static void main(String[] args) throws SQLException {
        Connection conn = DriverManager.getConnection(url, user, password);
        String sql = "delete from tbtest where id=?";
        PreparedStatement ps = conn.prepareStatement(sql);
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入id=？");

        int id = scanner.nextInt();
        ps.setInt(1,id);
        int i = ps.executeUpdate();
        System.out.println(i);

        try {
            if (ps!=null){
                ps.close();
            }

        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if (conn!=null){
                    conn.close();

                }
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                if (scanner != null) {
                    scanner.close();
                }

            }
        }
    }
}
